<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Register</title>
<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
	function checkName() {
		var username = $("#username").val();
		$.ajax({
			url : "checkName.do",
			type : "post",
			data : {
				"username" : username
			},
			dataType : "text",
			success : function(data) {
				if (data === "success") {
					$("#title").html("<h3 style='color:green;'>账号不存在,可以新增</h3>");
				} else if (data === "error") {
					$("#title").html("<h3 style='color:red;'>账号存在,不可以新增</h3>");
				}
			}
		})
	}
</script>
</head>
<body>
	<form action="add.do" method="get">
		<table border="1" cellspacing="0" align="center">
			<tr>
				<td>账号</td>
				<td><input id="username" type="text" name="username" onblur="checkName()" /><span id="title"></span></td>
			</tr>
			<tr>
				<td>密码</td>
				<td><input type="text" name="password" /></td>
			</tr>
			<tr>
				<td colspan="2"><button type="submit">注册</button></td>
			</tr>
			<tr>
				<td colspan="2"><a href="toLogin.do">返回</a></td>
			</tr>
		</table>
	</form>
</body>
</html>